package com.itheima.service.impl;

import com.itheima.entity.TbClueTrackRecord;
import com.itheima.dao.TbClueTrackRecordDao;
import com.itheima.service.TbClueTrackRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 线索跟进记录(TbClueTrackRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:53
 */
@Service("tbClueTrackRecordService")
public class TbClueTrackRecordServiceImpl implements TbClueTrackRecordService {
    @Resource
    private TbClueTrackRecordDao tbClueTrackRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbClueTrackRecord queryById(Long id) {
        return this.tbClueTrackRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbClueTrackRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbClueTrackRecord> queryByPage(TbClueTrackRecord tbClueTrackRecord, PageRequest pageRequest) {
        long total = this.tbClueTrackRecordDao.count(tbClueTrackRecord);
        return new PageImpl<>(this.tbClueTrackRecordDao.queryAllByLimit(tbClueTrackRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbClueTrackRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TbClueTrackRecord insert(TbClueTrackRecord tbClueTrackRecord) {
        this.tbClueTrackRecordDao.insert(tbClueTrackRecord);
        return tbClueTrackRecord;
    }

    /**
     * 修改数据
     *
     * @param tbClueTrackRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TbClueTrackRecord update(TbClueTrackRecord tbClueTrackRecord) {
        this.tbClueTrackRecordDao.update(tbClueTrackRecord);
        return this.queryById(tbClueTrackRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tbClueTrackRecordDao.deleteById(id) > 0;
    }
}
